<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模块列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" th:href="@{/resource/css/bootstrap.min.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/font-awesome.min.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/animate.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/style.css}" />
    <link th:href="@{/resource/css/plugins/sweetalert/sweetalert.css}" rel="stylesheet">
    <link th:href="@{/resource/css/plugins/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/resource/css/plugins/toastr/toastr.min.css}" />

</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="row">
                        <div class="col-sm-10">  <h5>模块管理 &nbsp;/&nbsp;  <small>模块编辑</small></h5></div>
                        <div class="col-sm-2">
                            <button type="button"  id="back_but" class="btn btn-white">返回</button>
                        </div>
                    </div>
                </div>
                <div class="ibox-content">
                <form class="form-horizontal m-t" id="commentForm" method="post">

                <div class="form-group">
                    <div class="col-md-7">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-9">
                                <input id="title" type="text" class="form-control" name="title" required="" aria-required="true" th:value="${modeModel.title}">
                                <input id="id" type="hidden" class="form-control" name="id" required="" aria-required="true" th:value="${modeModel.id}">
                                <input id="type_tv" type="hidden" class="form-control" name="type_tv" required="" aria-required="true" th:value="${modeModel.type}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">类型：</label>
                            <div class="col-sm-9">
                                <select class="form-control" name="type" id="type">
                                    <option value="0">轮播广告</option>
                                    <option value="1">专题</option>
                                    <option value="2">弹窗广告</option>
                                    <option value="3">欢迎广告</option>
                                    <option value="4">首页图快</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">开始时间：</label>
                            <div class="col-sm-9">
                                <input id="endtime" type="text" class="form-control" name="endtime" required="" aria-required="true" th:value="${modeModel.endtime}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">结束时间：</label>
                            <div class="col-sm-9">
                                <input id="starttime" type="text" class="form-control" name="starttime" required="" aria-required="true" th:value="${modeModel.starttime}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">状态：</label>
                            <div class="col-sm-9">
                                <select class="form-control" name="type" id="flag">
                                    <option value="0">启用</option>
                                    <option value="-1">下架</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">排序：</label>
                            <div class="col-sm-9">
                                <input id="orderno" type="text" class="form-control" name="orderno" required="" aria-required="true" th:value="${modeModel.orderno}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">点击数：</label>
                            <div class="col-sm-9">
                                <input id="clicks" type="text" class="form-control" name="clicks" required="" aria-required="true" th:value="${modeModel.clicks}">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" id="model_submit" type="button">提交</button>
                                <button class="btn btn-white" id="model_show" type="button">预览</button>
                            </div>
                        </div>

                        </div>
                    </div>

                  </form>

                <!-- End Example Events -->

            </div>
        </div>
    </div>

        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="row">
                        <div class="col-sm-10">  <h5>展示图</h5></div>
                        <div class="col-sm-2">
                        </div>
                    </div>
                </div>
                <div class="ibox-content">
                    <div style="height: 150px;align-content: center">
                        <img  id="icon_img" style="max-width: 760px;max-height: 400px;" th:src="${'http://ou3sldl51.bkt.clouddn.com/'+modeModel.icon}"/>
                    </div>
                    <a href="javascript:;" class="file">选择文件
                        <input type="file" name="fileToUpload" id="fileToUpload"  onchange="ajaxFileUpload()" multiple="multiple"/>
                    </a>


                    <input id="icon" type="hidden" name="icon" required="" aria-required="true" class="form-control" th:value="${modeModel.icon}">

                    </p>
                </div>
            </div>
        </div>

    </div>


</div>




<div th:include="footer"></div>

<script type="text/javascript" th:src="@{/script/js/biz/product/favorite.js}"></script>
<script type="text/javascript" th:src="@{/script/js/ajaxfileupload.js}"></script>

<script>
    $(function () {
        $("#type").val($("#type_tv").val());
    });




    $("#model_submit").click(function () {
        var title = $("#title").val();
        var type = $("#type").val();
        var icon = $("#icon").val();
        var flag = $("#flag").val();
        var id = $("#id").val();
        var starttime = $("#starttime").val();
        var endtime = $("#endtime").val();
        var clicks = $("#clicks").val();
        var orderno = $("#orderno").val();
        var mydata = '{"id":"' + id + '","title":"'  + title + '","type":"'+type+'","icon":"'+icon+'","type":"'+type+'","flag":"'+flag+'","starttime":"'+starttime+'","endtime":"'+endtime+'","clicks":"'+clicks+'","orderno":"'+orderno+'"}';
        $.ajax({
            url: "/common/model/updateModel",
            type: "post",
            data: mydata,
            contentType: "application/json",
            dataType:"json",
            success: function (data) {
                if(data["retType"] == "0") {
                    toastr.success("修改成功!");
                    setTimeout( "window.location.href='/common/model/doModelPage'",2000);//延时3秒

                } else {
                    toastr.error(data["retMsg"]);
                }
            }
        });
    });

    function ajaxFileUpload() {
        var imgurl = "http://ou3sldl51.bkt.clouddn.com/";
        $.ajaxFileUpload({
            url : '/common/upload/special', //用于文件上传的服务器端请求地址
            secureuri : false, //是否需要安全协议，一般设置为false
            fileElementId : 'fileToUpload', //文件上传域的ID
            type: "post",
            dataType : 'json', //返回值类型 一般设置为json
            success : function(data, status)//服务器成功响应处理函数
            {
                $("#icon_img").attr("src", imgurl+data.key);
                $("#icon").val(data.key);
            },
            error : function(data, status, e)//服务器响应失败处理函数
            {
                toastr.success("文件上传失败!");
            }
        })
        return false;
    }

</script>
</body>
</html>